longest substring with at most k distinct characters